/*
 * @Author: zhangfeng
 * @Date: 2024-01-09 11:56:38
 * @LastEditTime: 2024-01-09 15:37:58
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \manager\managersystem\src\directives\permission\permission.ts
 * © 2023 张峰，All rights reserved.
 */
import type { Directive } from 'vue';

import { menusList } from '../../store/index';

export const permission: Directive = (el, binding) => {
	const storeMenulist = menusList();
	const permissionAll = storeMenulist.premis;
	const { value: permissions } = binding;
	if (Array.isArray(permissions) && permissions.length > 0) {
		const hasPermissions = permissionAll.some((permis: string) => {
			return permissions.includes(permis);
		});
		if (!hasPermissions) {
			el.parentNode?.removeChild(el);
		}
	} else {
		throw new Error(`permission.hasPermission`);
	}
};
